<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box_father{
            width: 500px;
            height: 40px;
            position: relative;
        }
        .box_father input{
            width: inherit;
            height: inherit;
            outline: none;
            border: none;
            background-color: #F5F5F5;
            border-radius: 5px;
            padding-left: 10px;
            border-color: #FFAE39;
            box-sizing: border-box;
            transition: all .5s;
        }
        .opc{
            position: absolute;
            color:#736A88;
            left: 2%;
            top: 50%;
            z-index: 99;
            transform: translateY(-50%);
            transition: all .5s;
        }
        .active{
            font-size: 10px;
            top:-10%;
            transform: translateX(-50%);
        }
    </style>
</head>
<body>
    <div class="box_father">
        <input type="text" id="texts">
        <span class="opc">你好</span>
    </div>
    
</body>
</html>

<script>
    var texts = document.getElementById("texts")
    var opc = document.querySelector(".opc")
    texts.addEventListener("focus",function(){
        opc.classList.add("active")
    })
    texts.addEventListener("blur",function(){
        if(!texts.value){
            opc.classList.remove("active")
        }
    })
</script>

